package com.tezign.intelligence.mini.dam.aifamilyconsultant.bean;

import com.tezign.intelligence.mini.dam.aifamilyconsultant.constant.CodeInterFace;
import lombok.Getter;
import lombok.Setter;

/**
 * @author wuzhiwei
 * @team M
 * @owner wuzhiwei
 * @Date 2022/3/14
 */
@Getter
@Setter
public class ResponseBean<T> {
	private static final long serialVersionUID = 1L;

	private String code;

	private String message;

	private T result;


	public ResponseBean() {
	}

	public ResponseBean(CodeInterFace code) {
		this(code, null);
	}

	public ResponseBean(CodeInterFace code, T result) {
		this.code = code.getCode();
		this.message = code.getMessage();
		this.result = result;
	}


	public ResponseBean<T> success(T result) {
		this.code = RequestStatusEnum.SUCCESS.getCode();
		this.message = RequestStatusEnum.SUCCESS.getMessage();
		this.result = result;
		return this;
	}


	public ResponseBean<T> forbidden() {
		this.code = RequestStatusEnum.FORBIDDEN_OPERATION.getCode();
		this.message = RequestStatusEnum.FORBIDDEN_OPERATION.getMessage();
		this.result = null;
		return this;
	}

	public ResponseBean<T> exception() {
		this.code = RequestStatusEnum.EXCEPTION.getCode();
		this.message = RequestStatusEnum.EXCEPTION.getMessage();
		this.result = null;
		return this;
	}

	public ResponseBean<T> exception(CodeInterFace code) {
		this.code = code.getCode();
		this.message = code.getMessage();
		this.result = null;
		return this;
	}

	public ResponseBean<T> notFound() {
		this.code = RequestStatusEnum.NOT_FOUND.getCode();
		this.message = RequestStatusEnum.NOT_FOUND.getMessage();
		this.result = null;
		return this;
	}

	public ResponseBean<T> badParameter() {
		this.code = RequestStatusEnum.BAD_REQUEST.getCode();
		this.message = RequestStatusEnum.BAD_REQUEST.getMessage();
		this.result = null;
		return this;
	}


}
